package com.offcn.dao;

import com.offcn.entity.Book;
import com.offcn.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class BookDao {
    public List<Book> queryAllBooks() throws SQLException {
        Connection conn = DruidUtils.getConnection();
        String sql = "select * from book";
        QueryRunner qr = new QueryRunner();
        List<Book> query = qr.query(conn, sql, new BeanListHandler<Book>(Book.class));
        conn.close();
        return query;
    }
}
